home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 2: Applications
/
Linux Cubed Series 2 - Applications.iso
/
tex
/
ntex
/
get_ntex
< prev
next >
Wrap
Text File
|
1996-11-16
|
21KB
|
605 lines
#!/bin/bash
# (is this the correct PATH of `bash'?,
# try also: `#!/usr/bin/bash')
#
# The DOCUMENTATION can be found at the end of the script
#
# Copyright Volker B"orchers 1996
# email: boercher@physik.uni-bremen.de
#
SCRIPTNAME="get_ntex"
## enable function caching:
set -h
## enable debugging:
##set -x
##>>>>>>>>>>>>>>> Default settings: >>>>>>>>>>>>>>>>
## darfnix (please use one of the mirrors close to you!):
#SITE="darfnix.mathematik.uni-stuttgart.de"
#NTEXDIR="/pub/tex/ntex/ntex"
## sunsite (look for mirrors):
#SITE="sunsite.unc.edu"
#NTEXDIR="/pub/Linux/apps/tex/ntex"
## official TeX sites:
#NTEXDIR="/tex-archive/systems/unix/linux/ntex"
#SITE="ftp.dante.de" # (Germany)
#SITE="ftp.shsu.edu" # (USA)
#SITE="ftp.tex.ac.uk" # (UK)
LOCDIR="$PWD" # (You MUST use a absolute path!)
DIRS="base extras fixes fonts japanese languages sources systems ntex"
## nb- nx- * * nf- nj- nl- ns- NTeX-bi * *
## (translation into filename prefixes)
## Special actions. Valid values are:
## `all': get whole distribution (option `-a')
## `update': get latest update (option `-u')
## `index': get index/description files (option `?')
SPECIAL=""
## The alias for all the Files in the NTeX `root' directory:
ROOT="BUGS CHANGES INDEX INSTALL NTeX.announce NTeX.lsm README.NTeX RELEASE"
## The list of files to get if the option was `?' (at least `INDEX'!):
QUEST="CHANGES INDEX NTeX.lsm README.NTeX RELEASE"
## The NTeX version that you have now (needed for the `-u' option,
## i.g. updating means to get all files that changed since CURR_VERSION):
CURR_VERSION=2.0.2
## For the `-u' option: Files that will be updated with every
## new release
EVERYUPDATE="$ROOT ntex"
## Temporary files:
TMPFILE="/tmp/get_ntex.tmp.$$"
TMPlst="/tmp/get_ntex.lst.$$"
TMPftp="/tmp/get_ntex.ftp.$$"
trap "rm -f $TMPFILE $TMPlst $TMPftp" 0 1 2 15
rm -f $TMPFILE $TMPlst $TMPftp # (for security reasons!)
echo -n > $TMPlst
##<<<<<<<<<<<<<<<< Default settings <<<<<<<<<<<<<<<<<<<<
BEGINTIME="`date`"
######## add_to_listfile ################################
## has one argument: a file containing files/packages or
## directories to get. From the file all comments (`#')
## are stripped and every name (originally separated by
## whitespace or `,') will be put into one line. (We have
## to force `awk' to recalculate the lines.)
## The result will be appended to TMPlst.
function add_to_listfile () {
sed "s,#.*,," $1 \
| awk '{ OFS="\n"; FS=","; $(NF+1) = ""; print }' \
| awk '{ OFS="\n"; $(NF+1) = ""; print }'>> "$TMPlst"
}
##########################################################
############# Get options and variables: #################
if [ -z "$1" ]; then
ERROR=1
else
LSTFILE="" #(accept no default for this)
while [ -n "$1" ]; do
case $1 in
?) SPECIAL="$SPECIAL index"; shift;;
-f*) LSTFILE="${1#-?}"; shift
[ -z $LSTFILE ] && { LSTFILE=$1; shift }
add_to_listfile "$LSTFILE";;
-s*) SITE="${1#-?}"; shift
[ -z $SITE ] && { SITE=$1; shift };;
-n*) NTEXDIR="${1#-?}"; shift
[ -z $NTEXDIR ] && { NTEXDIR=$1; shift };;
-l*) LOCDIR="${1#-?}"; shift
[ -z $LOCDIR ] && { LOCDIR=$1; shift }
if [ "${LOCDIR#/}" = "$LOCDIR" ]; then
echo -e "\a(STOP) Local Directory $LOCDIR must be\
\nspecified with an absolute path! No actions performed."
exit 1
fi;;
-a) SPECIAL="$SPECIAL all"; shift;;
-u) SPECIAL="$SPECIAL update";
SET_CURR_VERSION="${1#-?}"; shift
[ -z "$SET_CURR_VERSION" ] && { SET_CURR_VERSION=$1; shift }
[ -n "$SET_CURR_VERSION" ] && CURR_VERSION=$SET_CURR_VERSION;;
*) echo "$*" > "$TMPFILE"
add_to_listfile "$TMPFILE"
break;;
esac
done
## (Note: There is no consistency check)
fi
## remove eventually trailing `/' from directories:
LOCDIR="${LOCDIR%/}"
NTEXDIR="${NTEXDIR%/}"
######################################################
################### FUNCTIONS: #######################
# (We had to set the variables before)
######## create_dir ###################################
## Creates a directory (relative or absolute path)
## This works: `create_dir /tmp/tmp1/tmp2' (with neither
## `/tmp/tmp1' nor `tmp/tmp1/tmp2' already existing)
function create_dir () {
while ! [ -d $1 ]; do
dir="$1"
while ! [ -d "$dir" ]; do
[ -z "$dir" ] && break
mkdir "$dir" 2>/dev/null || dir="${dir%/*}"
done
done
[ -d $1 ] && return 0
return 1
}
######## rtn_dir ########################################
## Returns the name of the directory where the file is
## expected to be in, e.g. `rtn_dir nb-cm' returns `base'
function rtn_dir () {
case $1 in
nb-*) echo "base"; return 0;;
nx-*) echo "extras"; return 0;;
nf-*) echo "fonts"; return 0;;
nj-*) echo "japanese"; return 0;;
nl-*) echo "languages"; return 0;;
ns-*) echo "sources"; return 0;;
NTeX-bin*) echo "systems"; return 0;;
*) return 1;;
esac
}
######## get_index ######################################
## gets not only the file INDEX from SITE but all files
## specified by $QUEST:
function get_index () {
cd $LOCDIR
echo "> Connecting to $SITE ..."
ftp $SITE << EOF
cd $NTEXDIR
prompt
mget $QUEST
bye
EOF
if [ -s INDEX ]; then
echo "> Look for the files"
echo -e "> $tab $QUEST"
echo "> in directory $LOCDIR"
else
echo -e "\a>>>> (ERROR) Unable to get the INDEX file.\
\n>>>> Check site, local and remote directory settings!"
fi
}
######## get_all ########################################
## gets the whole distribution as one big `.tar' file
## (Only) at `darfnix.mathematik...' the directory `ntex'
## is a symbolic link to a directory with the name
## `ntex-RELEASE-No.' e.g. `ntex-2.0.2'. The `tar' at
## darfnix will only tar the link (and this is not what we want!).
## At all other sites there is only the directory `ntex' and
## we don't have to worry about the release
function get_all () {
cd $LOCDIR
if [ "${SITE#darfnix}" != "$SITE" ]; then
# We have to know the release number (if not specified
# on the command line):
if [ -z "$Release" ]; then
echo "> Connecting to $SITE (get RELEASE) ..."
ftp $SITE << EOF
cd $NTEXDIR
get RELEASE
bye
EOF
if ! [ -s RELEASE ]; then
echo -e "\a>>>> (ERROR) Unable to get the REALESE file.\
\n>>>> Check site, local and remote directory settings!"
return 1
fi
Release="-`grep release RELEASE | sed 's/.*=//'`"
fi
else
Release=""
fi
# Now really get the distribution:
echo "> Connecting to $SITE ..."
ftp $SITE << EOF
cd $NTEXDIR
cd ..
bin
get ntex$Release.tar
bye
EOF
if [ -s ntex$Release.tar ]; then
echo "> The NTeX distribution is the \`tar' file"
echo -e "> $tab $LOCDIR/ntex$Release.tar"
echo "> Unpack it with \"tar -xvf ntex$Release.tar\""
echo "> (This creates the directory ntex$Release)"
else
echo -e "\a>>>> (ERROR) Unable to get the whole distribution.\
\n>>>> Check site, local and remote directory settings!"
fi
}
######## get_update_list ################################
## tries to get the file CHANGES from SITE and evaluate it
## according to the CURR_VERSION setting to extract the names
## of the files that changed since CURR_VERSION.
## (The idea for the method comes from Frank Langbein):
function get_update_list () {
cd $LOCDIR
echo "> Connecting to $SITE to get CHANGES ..." 1>&2
ftp $SITE 1>&2 << EOF
cd $NTEXDIR
get CHANGES
bye
EOF
if [ -s CHANGES ]; then
## determine if CURR_VERSION < ACT_VERSION:
ACT_VERSION=$(egrep '^NTeX V[1-9]' CHANGES \
| cut -dV -f2 \
| cut -d, -f1 \
| tr -d '.' \
| awk -v current=`echo $CURR_VERSION | tr -d '.'` \
'{if ($1 > current) {
print substr($1,1,1) "." substr($1,2,1) "." substr($1,3,1)
exit
}}')
if [ -n "$ACT_VERSION" ]; then
update_file=$LOCDIR/update-`date +"%d.%b.%y"`
echo -n > $update_file
egrep '^N(.-|TeX V[1-9])' CHANGES | cut -d, -f1 \
| sed -e "s,NTeX V,#release," -e "s, V.*\$,," -e 's,^.*Changes$,,' \
| tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' \
| awk -v current=$CURR_VERSION 'BEGIN { doprint=1 } {
if(doprint==1) {
print $1; if($0 ~ current) {doprint=0}
}}' \
> $TMPFILE
## ("tr 'A-Z' 'a-z'" did not work on some machines)
echo "#Things that change with every release:" >> $TMPFILE
echo "$EVERYUPDATE" >> $TMPFILE
grep -v "\*" $TMPFILE > $update_file
## to cope with wildcards in changes (e.g. ns-*) -
## we then have to get the whole directory
WILDCARDS="`grep '\*' $TMPFILE`"
for this in $WILDCARDS; do
rtn_dir $this >> $update_file
done
echo -e \
"> Updating from current version $CURR_VERSION to release $ACT_VERSION.\
\n> The names of the updated packages can be found in $UPDATE_LIST" 1>&2
echo "$update_file"
else
echo -e "\a>>>> You already have the latest NTeX version ($CURR_VERSION)\
\n>>>> - Nothing to do." 1>&2
## is the following line OK (is /dev/null really empty?) ???
echo "/dev/null"
fi
return 0
else
echo -e "\a>>>> (ERROR) Unable to get the file CHANGES.\
\n>>>> Check site, local and remote directory settings"
## is the following line OK (is /dev/null really empty?) ???
echo "/dev/null"
return 1
fi
}
######################################################
################### STARTUP: #########################
tab="\40"
USE="\a* USAGE:\
\n*\t $SCRIPTNAME [options] [packages]\
\n*+ Options:\
\n* $tab \`?'\t\t\tGet some files that helps you to decide which \
\n*\t\t\t$tab packages you want. (INDEX, CHANGES, ...) \
\n* $tab \`-f file'\t\t\`file' should contain a list of packages (e.g.\
\n*\t\t\t$tab \`nb-ltx2e') and/or directories (base, extras, ..)\
\n* $tab \`-s Site'\t\tThe NTeX site\
\n* $tab \`-n NTeX dir'\tThe full path of the NTeX directory at the site\
\n* $tab \`-l local dir'\tThe directory to place NTeX (the \"root\"\
\n*\t\t\t$tab directory where the subdirs \`base', \`extra' are in)\
\n* $tab \`-u' [current_version] $tab Get all packages that changed\
\n* \t\t\t$tab since \`current_version'. The default for the\
\n* \t\t\t$tab optional \`current_version' is \`$CURR_VERSION'.\
\n* $tab \`-a' [release]\tGet the whole NTeX distribution as one big \`.tar'\
\n* \t\t\t$tab file. (WARNING: >35MB!) The optional \`release'\
\n* \t\t\t$tab (e.g. \`2.0.2') only makes sense on SITE \`darfnix'.\
\n* \t\t\t$tab If it's not specified get latest official release.\
\n*+ Defaults:\
\n* $tab Site=\"$SITE\"\
\n* $tab NTeX dir=\"$NTEXDIR\"\
\n* $tab local dir=\"$LOCDIR\"\
\n* $tab Special actions=\"$SPECIAL\"\
\n* $tab Current version=\"$CURR_VERSION\""
EXAMPLE="*+ How to specify the files/packages you want? \
\n* $tab (The syntax for the command line and for the \
\n* $tab \`file' (with \`-f' option) is the same!) \
\n- - - - - - - - - A sample file: - - - - - - - - - \
\n# Everything after a \`#' will be ignored. \
\n# First we want the complete directory \`ntex': \
\nntex/ \t# (it contains the basic installation files) \n\
\n# Then all basic packages (as a directory) \
\nbase \t# (the trailing \`/' is optional) \n\
\n# Some other packages (extras, a font and 2 language specific): \
\nextras/nx-feynm.pkg,nx-bibl nx-music, nf-bbold \
\nlanguages/nl-russ.pkg, nl-thai \
\n# Note that you can mix different ways to specify them: \
\n# + Files may be separated by whitespace and/or commas. \
\n# + For packages with a basename \`n?-'... (e.g. nl-russ, nx-bibl), \
\n# $tab you can do without the path and the suffix \`.pkg'! \n\
\n# Now we want the binaries for Linux and for AIX machines - \
\n# the path and suffix \`release.tar.gz' is also NOT required: \
\nsystems/NTeX-bin-i486-linux-2.1.0.tar.gz NTeX-bin-AIX\n\
\n# At last we want all regular files in the NTeX-\`root' directory \
\n# (CHANGES, INDEX, INSTALL, README.NTeX, ...). For this there is \
\n# a special KEYWORD: \
\nroot \
\n----------------- End of the example file ----------"
VERSION="* $0, version 1.0, 04/23/1996"
echo "$VERSION"
## only a little check:
if [ -z "$SITE" -o -z "$NTEXDIR" -o -z "$LOCDIR" ]; then
echo -e "\a> Missing Argument or missing default setting:\
\n> Site=\"$SITE\", Lokal dir.=\"$LOCDIR\", NTeX dir.=\"$NTEXDIR\"\
\n\n$USE"
exit 1
fi
## print help message, if script is called without arguments:
[ "$ERROR" = 1 ] \
&& { echo -e "$USE\n\n$EXAMPLE"; exit 1 }
## create the local directories (if they don't exist).
## The directory structure is the same as in SITE:
[ -d $LOCDIR ] || create_dir $LOCDIR
if ! cd $LOCDIR; then
echo -e "\a(STOP) Local Directory $LOCDIR doesn't exist!\
\nNo actions performed."
exit 1
else
mkdir $DIRS >&/dev/null
cd $OLDPWD
fi
{ grep "$SITE" $HOME/.netrc > /dev/null \
|| grep "default" $HOME/.netrc > /dev/null }\
|| { echo -e "\a(STOP) ~/.netrc not configured.\
\nAdd one of the following two lines to it:\
\n $tab machine $SITE login anonymous password YOUR_EMAIL_ADDRESS\
\nor: $tab default login anonymous password YOUR_EMAIL_ADDRESS\
\nand shut it for all others by \"chmod 600 ~/.netrc\""; exit 1 }
##########################################################
################## MAIN: #################################
for this in $SPECIAL; do
case $this in
index) get_index ;;
all) get_all ;;
update) UPDATE_LIST=`get_update_list`
add_to_listfile $UPDATE_LIST;;
*) echo -e "\a(STOP) No such SPECIAL \`$this'"; exit1;;
esac
done
## Now every information about files to get (from the command
## line, from the `-f' or `-u' option) is contained in TMPlst.
## files don't have to be specified with an absolute path
if grep "^/" $TMPlst >&/dev/null; then
echo -e "\a>>>> (ERROR) The following files will be ignored:"
grep "^/" $TMPlst
echo "<<< (Don't use absolute pathnames)"
fi
############# some monster pipes: ###################
####### 1) the packages:
## all requested packages should be specified the same way:
## `nb-ltx2e' - without path and `.pkg' suffix
## (every filename starting with `n', followed by an arbitrary
## letter followed by `-' is assumed to be a package!)
packs="`grep "^n.-" $TMPlst \
| sed 's,.*/,,g' \
| sed 's,\..*,,g' \
| sort | uniq`" 2>/dev/null
####### 2) the binary packages:
bins="`grep 'NTeX-bin-' $TMPlst \
| sed 's,.*/,,g' \
| sed 's,.tar.gz,,'`"
####### all other:
grep -v '^n.-' $TMPlst \
| egrep -v '(^/)|(NTeX-bin-)' \
| sed "s,/\$,," \
| sort | uniq >$TMPFILE 2>/dev/null
####### 3) the directories `base', `extras', ...:
## (force awk to recalculate a line)
dir_reg_expr="/^(`echo $DIRS | awk '{OFS=")|(";
$(NF+1)=""; NF=NF-1; print}'`)$/"
dirs=`grep -v "/" $TMPFILE | awk "$dir_reg_expr"`
####### 4) other files:
## duplicate the lines containing DIRS and BINS:
for this in $dirs; do echo -e $this >> $TMPFILE; done
## remove lines that appear more than once
other=`sort $TMPFILE | uniq -u`
########### create a ftp batchfile: #################
## clean the ftp batchfile:
echo -n > $TMPftp
echo "bin" >> $TMPftp
## complete subdirectories of NTEXDIR
## (we assume, that the server understands the meaning
## of appending the `.tar' suffix to the directory name)
if [ -n "$dirs" ]; then
echo "cd $NTEXDIR" >> $TMPftp
echo "lcd $LOCDIR" >> $TMPftp
for this in $dirs; do
echo "get $this.tar" >> $TMPftp
## unpacking should be done after the script has ended
## not this: echo "! tar -xf $this.tar &" >> $TMPftp
## but this:
echo "> Get directory $this as a \`.tar' file. Unpack it"
echo "> with tar -xvf $this.tar"
done
fi
## binary packages:
if [ -n "$bins" ]; then
echo "cd $NTEXDIR/systems" >> $TMPftp
echo "lcd $LOCDIR/systems" >> $TMPftp
# mget allowes to do without release and `tar.gz' suffix.
# (This also allowes to easyly specify ALL binarys with
# `NTeX-bin-'!)
echo "prompt" >> $TMPftp
for this in $bins; do
echo "mget $this*" >> $TMPftp
done
echo "prompt" >> $TMPftp
fi
## packages:
last_dir=""
if [ -n "$packs" ]; then
for this in $packs; do
this_dir=`rtn_dir $this` \
|| { echo -e "\a>>>> (INTERNAL ERROR) \`$this' is\
no package."; continue }
if [ "$this_dir" != "$last_dir" ]; then
echo "cd $NTEXDIR/$this_dir" >> $TMPftp
echo "lcd $LOCDIR/$this_dir" >> $TMPftp
last_dir=$this_dir
fi
echo "get $this.pkg" >> $TMPftp
done
fi
## other:
if [ -n "$other" ]; then
echo "cd $NTEXDIR" >> $TMPftp
echo "lcd $LOCDIR" >> $TMPftp
last_dir=""
for this in $other; do
## get all the (regular) files in NTEXDIR ?:
if [ $this = "root" ]; then
echo "cd $NTEXDIR" >> $TMPftp
echo "prompt" >> $TMPftp
echo "mget $ROOT" >> $TMPftp
echo "prompt" >> $TMPftp
continue
fi
this_file="${this##*/}"
this_dir="${this%/*}"
[ "$this_file" = "$this_dir" ] && this_dir=""
if [ "$this_dir" != "$last_dir" ]; then
echo "cd $NTEXDIR/$this_dir" >> $TMPftp
echo "lcd $LOCDIR/$this_dir" >> $TMPftp
last_dir=$this_dir
fi
echo "get $this_file" >> $TMPftp
done
fi
######### get the files using the batchfile: #########
if grep "get " $TMPftp >&/dev/null; then
echo "bye" >> $TMPftp
echo "> Connecting to $SITE ..."
ftp $SITE < $TMPftp
cp $TMPftp $LOCDIR
echo "> Ready! - A list of all actions performed on the site"
echo "> $SITE can be found in the file"
echo -e "> $tab $LOCDIR/get_ntex.ftp"
fi
echo "> \`$SCRIPTNAME' started at $BEGINTIME"
echo -ne "> \tand ended at\t"; date
## Cleanup
rm -f $TMPFILE $TMPlst $TMPftp
exit 0 ## <---END---OF---THE---SCRIPT
================== DOCUMENTATION: ==============================
This script provides an easy way to get NTeX- files or packages via
`ftp'. It is especially designed to be working at night when all your
compeditors are sleeping (see section `at night'). It has default
settings for the site to get NTeX from and for the directory where
NTeX is. (An example for the way to specify the files you want is
printed if you call the script without an argument.)
`get_ntex' first creates (on default in the current working
directory) all the directories that are contained in the
NTeX root directory at the site:
"base extras fixes fonts japanese languages sources systems ntex"
The script then gets the packages and files you specified and puts
them in the right subdirectories.
One note on getting the whole distribution (option `-a') and
complete subdirectories (e.g. `base'): You will only have one file
(e.g. `base.tar') instead of the files in the directories first.
You will have to unpack them with `tar -xf ...' (the skript will tell
you about that).
------------------- INSTALLATION: -----------------------------
1) If you want, try it immediately e.g. with
` get_ntex '
If it worked, `get_ntex' only gives you information on how to
use it (since you called the script without arguments).
Now call `get_ntex' with an argument! For example say:
` get_ntex nb-amstx '
If it really gets the `AmsTeX' package and puts it into the
`base' subdirectory of your local directory (./) everything
should be alright.
2) If there was the error `No such file or directory', the path
of bash is not correctly set. Try
` bash get_ntex nb-amstx '
If this worked you may want to set the correct path of `bash'
in the first line of this script. First find out
the absolute path of `bash':
in `csh': `which bash'
in `sh' or `bash': `type bash'
(LINUX-default is `/bin/bash', on UNIX often also
`/usr/local/bin/bash')
Then edit the first line of the script for the path of `bash'
3) For the automatic ftp login procedure you will need a file
`~/.netrc' with an entry for the site of your choice.
(Alternatively a `default' entry - but not all ftp daemons
support it). `get_ntex' will figure it out for itself if your
`~/.netrc' file exists and is OK or not, and will tell you what
to do, if not.
4) If you want edit the section between `>>> Default Settings: >>>'
and `<<< Default Settings: <<<'. The meaning of the variables are
explained there. (Especially think about the best SITE to get
NTeX from.)
5) Install `get_ntex' somewhere where the shell can
find it if you like it, else delete it!
------------------ at night: ----------------------------------
If you want to let your computer do the job at a given hour
(e.g. 23:55) you should say some hours before (when you are awake):
`at 23:55 << EOF
/PATH_OF_GET_NTEX/get_ntex -l `INSTALL_DIECTORY' -f `files_I_want'
EOF'
-> For every file use an absolute path!
-> Don't forget to specifiy the lokal directory!
---------------------- BUGS: ----------------------------------
* The script should be able to deal with wildcards
* The script has grown too big and is not as easy to understand as
I like it.
---------------------- ACKNOWLEDGEMENT: -----------------------
I have to thank Frank Langbein, the maintainer of NTeX, for his
engagement, for suggestions and help (especially with the `-u' option)
---------------------
If you find `get_ntex' useful, have suggestions, improvements,
... write to:
boercher@physik.uni-bremen.de